package com.haixue.android.academy.activity;

import android.academy.haixue.com.haixue.R;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.haixue.android.academy.domain.User;
import com.haixue.android.academy.fragment.ExamFragment;
import com.haixue.android.academy.fragment.GoodsFragment;
import com.haixue.android.academy.fragment.LiveFragment;
import com.haixue.android.academy.fragment.PersonFragment;

import java.io.Serializable;

import butterknife.InjectView;

public class HomeActivity extends BaseSelectCategoryActivity {
    private static String mTextviewArray[] = { "课程", "直播", "题海", "个人" };
    private Class fragmentArray[] = { GoodsFragment.class, LiveFragment.class,
            ExamFragment.class, PersonFragment.class };

    private int mImageViewArray[] = { R.drawable.tab_curriculum,
            R.drawable.tab_live, R.drawable.tab_exam,
            R.drawable.tab_person };



    @InjectView(android.R.id.tabhost)
    FragmentTabHost mTabHost;

    private LayoutInflater layoutInflater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

    }

    @Override
    protected void initViews() {
        super.initViews();
        layoutInflater = LayoutInflater.from(this);
        tv_title.showSelectCategoryTitle();
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
        mTabHost.getTabWidget().setDividerDrawable(null);

        int count = fragmentArray.length;

        for (int i = 0; i < count; i++) {
            TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i])
                    .setIndicator(getTabItemView(i));
            mTabHost.addTab(tabSpec, fragmentArray[i], null);
//            mTabHost.getTabWidget().getChildAt(i)d
//                    .setBackgroundResource(R.drawable.selector_tab_background);
        }
    }

    private View getTabItemView(int index) {
        View view = layoutInflater.inflate(R.layout.tab_item_view, null);

        ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
        imageView.setImageResource(mImageViewArray[index]);

        TextView textView = (TextView) view.findViewById(R.id.textview);
        textView.setText(mTextviewArray[index]);

        return view;
    }

    @Override
    protected void initDatas() {
        super.initDatas();
        Serializable data = getIntent().getSerializableExtra("data");
        if (data != null){
            userWapper = (User) data;
        }
    }

    @Override
    protected void onRefreshData(long data) {
        super.onRefreshData(data);
    }
}
